import random
class Genotype:
    
    def __init__(self, numOfGene):
        self.geneArray = []
        self.mutationRate = 0.5
        self.numOfGene = 0
        self.lowerBound = 1
        self.upperBound = 1000
        #now we assume that there are 4 traffic light in each cross
        self.numOfGene = numOfGene * 4
        for i in range(0, self.numOfGene):
            self.geneArray.append(random.randint(self.lowerBound, self.upperBound)) #initialize gene with random values
    
    
    def mutate(self):
        for i in range(0, self.numOfGene):
            if random.random() > self.mutationRate :
                self.geneArray[i] = random.randint(self.lowerBound, self.upperBound)
                
            
    def onePointCrossover(self, anotherParent, crossPointIndex = 1):
        firstParent = Genotype(self.numOfGene / 4)
        secondParent = Genotype(self.numOfGene / 4)
        resultArray = []
        #generate crossover point
        crossPointIndex = random.randint(1, len(self.geneArray))
        for i in range(0, self.numOfGene):
            if i < crossPointIndex :
                firstParent.geneArray.append(self.geneArray[i])
                secondParent.geneArray.append(anotherParent.geneArray[i])
            else :
                firstParent.geneArray.append(anotherParent.geneArray[i])
                secondParent.geneArray.append(self.geneArray[i])
        resultArray.append(firstParent)
        resultArray.append(secondParent)
        return resultArray
     
    def evaluateFitness(self):
        return random.randint(10, 10000)